<!DOCTYPE html>
<html lang="zh" xmlns:th="http://www.thymeleaf.org" >
<head>
    <th:block th:include="include :: header('新增设备管理')" />
    <th:block th:include="include :: datetimepicker-css" />
    <th:block th:include="include :: bootstrap-fileinput-css" />
</head>
<body class="white-bg">
    <div class="wrapper wrapper-content animated fadeInRight ibox-content">
        <select title="打印机列表：" style="display: none" id="select-printlist"></select>
        <div id="preview-list" style="display: none"></div>
        <form class="form-horizontal m" id="form-astDevice-add">
            <input type="hidden" id="imgList" name="imgList" >
            <div class="form-group">
                <label class="col-sm-3 control-label">选择库房：</label>
                <div class="col-sm-8">
                    <div class="input-group">
                        <input id="treeId" name="storeroomId" type="hidden" />
                        <input class="form-control" type="text" onclick="selectAstStoreroomTree()" id="treeName" readonly="true">
                        <span class="input-group-addon"><i class="fa fa-search"></i></span>
                    </div>
                </div>
            </div>

            <div class="form-group">
                <label class="col-sm-3 control-label">选择站点：</label>
                <div class="col-sm-8">
                    <div class="input-group">
                        <input id="siteId" name="siteId" type="hidden" />
                        <input class="form-control" type="text" onclick="selectAstSiteTree()" id="siteName" readonly="true" >
                        <span class="input-group-addon"><i class="fa fa-search"></i></span>
                    </div>
                </div>
            </div>

            <div class="form-group">
                <label class="col-sm-3 control-label is-required">设备状态：</label>
                <div class="col-sm-8">
                    <div class="radio-box" >
                        <input type="radio"  name="caozuoStatus" value="11" required>
                        <label>入库</label>
                    </div>
                    <div class="radio-box" >
                        <input type="radio"  name="caozuoStatus" value="10" required>
                        <label>入站</label>
                    </div>
                    <div class="radio-box" >
                        <input type="radio"  name="caozuoStatus" value="0" required>
                        <label>携带</label>
                    </div>
                </div>
            </div>

            <div class="form-group">
                <label class="col-sm-3 control-label is-required">设备名称：</label>
                <div class="col-sm-8">
                    <input id="deviceName" name="deviceName" class="form-control" type="text" required>
                </div>
            </div>

            <div class="form-group">
                <label class="col-sm-3 control-label">设备类型：</label>
                <div class="col-sm-8">
                    <select name="deviceType" class="form-control m-b" th:with="type=${@dict.getType('ast_device_type')}">
                        <option th:each="dict : ${type}" th:text="${dict.dictLabel}" th:value="${dict.dictValue}"></option>
                    </select>
                </div>
            </div>

            <div class="form-group">    
                <label class="col-sm-3 control-label">设备数量：</label>
                <div class="col-sm-8">
                    <input name="deviceNumber" class="form-control" type="number">
                </div>
            </div>
            <div class="form-group">    
                <label class="col-sm-3 control-label">单价：</label>
                <div class="col-sm-8">
                    <input name="devicePrice" class="form-control" type="number">
                </div>
            </div>
            <div class="form-group">    
                <label class="col-sm-3 control-label">型号：</label>
                <div class="col-sm-8">
                    <input id="deviceGuige" name="deviceGuige" class="form-control" type="text">
                </div>
            </div>

            <div class="form-group">
                <label class="col-sm-3 control-label">设备厂家：</label>
                <div class="col-sm-8">
                    <div class="input-group">
                        <input class="form-control" name="deviceFactory" type="text" id="deviceFactory" >
                        <span onclick="selectFactoryTree()" class="input-group-addon"><i class="fa fa-search"></i></span>
                    </div>
                </div>
            </div>

            <div class="form-group">    
                <label class="col-sm-3 control-label ">采购时间：</label>
                <div class="col-sm-8">
                    <div class="input-group date">
                        <input name="deviceProcureTime" class="form-control" placeholder="yyyy-MM-dd" type="text" >
                        <span class="input-group-addon"><i class="fa fa-calendar"></i></span>
                    </div>
                </div>
            </div>
            <div class="form-group">    
                <label class="col-sm-3 control-label">质保时长(年)：</label>
                <div class="col-sm-8">
                    <input name="warrantyDuration" class="form-control" type="number">
                </div>
            </div>

            <div class="form-group">
                <label class="col-sm-3 control-label">协议模式：</label>
                <div class="col-sm-8">
                    <input name="protocolMode" class="form-control" type="text">
                </div>
            </div>

            <div class="form-group">
                <label class="font-noraml">设备图片：</label>
                <div class="file-loading">
                    <input id="multipleFile" name="files" type="file" multiple>
                </div>
            </div>

            <div class="form-group">
                <label class="col-sm-3 control-label">备注：</label>
                <div class="col-sm-8">
                    <textarea name="remark" class="form-control"></textarea>
                </div>
            </div>

        </form>
    </div>
    <th:block th:include="include :: footer" />
    <th:block th:include="include :: datetimepicker-js" />
    <th:block th:include="include :: bootstrap-fileinput-js" />
    <th:block th:include="include :: dayin-js" />
    <script th:inline="javascript">
        var prefix = ctx + "asset/astDevice"
        $("#form-astDevice-add").validate({
            focusCleanup: true
        });

        function submitHandler() {
            var caozuoStatus = $('input[name="caozuoStatus"]:checked').val();
            console.log(caozuoStatus)
            var kufangId = $("#treeId").val()
            var siteId = $("#siteId").val()

            if(caozuoStatus==11 && !kufangId){
                $.modal.msgError("请选择库房");
                return
            }else if(caozuoStatus==10 && !siteId){
                $.modal.msgError("请选择站点");
                return
            }

            if ($.validate.form()) {
                $.operate.save(prefix + "/add", $('#form-astDevice-add').serialize(),function (res) {
                    dayin(res)
                });
            }
        }

        $("input[name='deviceProcureTime']").datetimepicker({
            format: "yyyy-mm-dd",
            minView: "month",
            autoclose: true
        });


        /*库房管理-新增-选择父库房管理树*/
        function selectAstStoreroomTree() {
            var options = {
                title: '库房选择',
                width: "380",
                url: ctx + "asset/astStoreroom/selectAstStoreroomTree/" + $("#treeId").val(),
                callBack: doSubmit
            };
            $.modal.openOptions(options);
        }
        function doSubmit(index, layero){
            var body = $.modal.getChildFrame(index);
            $("#treeId").val(body.find('#treeId').val());
            $("#treeName").val(body.find('#treeName').val());
            $.modal.close(index);
        }

        function selectFactoryTree() {
            var options = {
                title: '厂商选择',
                width: "380",
                url: ctx + "asset/astFactory/selectFactoryTree" ,
                callBack: doSubmit2
            };
            $.modal.openOptions(options);
        }
        function doSubmit2(index, layero){
            var body = $.modal.getChildFrame(index);
            $("#deviceFactory").val(body.find('#treeName').val());
            $.modal.close(index);
        }

        /*站点管理-新增-选择父站点管理树*/
        function selectAstSiteTree() {
            var options = {
                title: '站点管理选择',
                width: "380",
                url: ctx + "asset/astSite/selectAstSiteTree/" + $("#treeId").val(),
                callBack: doSubmitSite
            };
            $.modal.openOptions(options);
        }

        function doSubmitSite(index, layero){
            var body = $.modal.getChildFrame(index);
            $("#siteId").val(body.find('#treeId').val());
            $("#siteName").val(body.find('#treeName').val());
            $.modal.close(index);
        }

        $("#multipleFile").fileinput({
            uploadUrl: ctx + 'common/uploads',
            uploadAsync: false
        }).on('filebatchuploadsuccess', function (event, data, previewId, index) {
            var rsp = data.response;
            var imgList = $("#imgList").val()
            if(imgList){
                imgList = imgList+","+rsp.urls
                $("#imgList").val(imgList)
            }else{
                $("#imgList").val(rsp.urls)
            }
        }).on('fileremoved', function (event, id, index) {
            $("input[name='" + event.currentTarget.id + "']").val('')


        }).on('fileclear', function (event, id, index) {
            $("#imgList").val("")
        }).on('filesuccessremove', function (event, id, index) {
            console.log('shanchuccccc'+ $("input[name='" + event.currentTarget.id + "']").val())
            console.log(id+'shanchuccccc'+ $("#"+id).val())
        })

        function dayin(result) {
            if (result.code == web_status.SUCCESS){
                var deviceName = $("#deviceName").val()
                var xinghao = $("#deviceGuige").val()
                var gongsi = $("#deviceFactory").val()
                for(var str of result.data){
                    console.log('===chengong1231231313')
                    drawTableTest(deviceName,xinghao,gongsi,str)
                }
            }
        }


    </script>
</body>
</html>